<template>
  <div class="admin-index">
    <div class="welcome-panel">
      <div class="home-info1">
        <el-row>
          <el-col :span="16">
            <div class="media">
              <div class="media-left">
                <el-avatar :size="60" :src="project.logo | imgPath">
                  <img src="~@/assets/img/default2.png" style="width: 60px">
                </el-avatar>
              </div>
              <div class="media-body">
                <div class="display-flex">
                  <div class="box3 title text-ellipsis">
                    {{ project.screenName }}
                  </div>
                  <div class="box1">
                    <!-- <i class="el-icon-edit-outline"/> -->
                    <!--  @click="editHandle"  -->
                  </div>
                </div>
                <div class="txt txt2">动火等级： {{ project.hotLevel }}</div>
                <div class="txt txt2">
                  <!-- 项目编号： {{ project.welderNumber }} -->
                </div>
                <div class="txt text-ellipsis">
                  <i class="icon-rili iconfont" />
                  {{ project.startTime | dateFormat("YYYY-MM-DD HH:mm:ss") }}-{{
                    project.endTime | dateFormat("YYYY-MM-DD HH:mm:ss")
                  }}
                </div>
                <div class="txt text-ellipsis">
                  <i class="icon-weizhi iconfont" />
                  {{ project.provinceName }}{{ project.cityName
                  }}{{ project.countyName }}{{ project.streetName
                  }}{{ project.address }}
                </div>
              </div>
            </div>
          </el-col>
          <el-col :span="8">
            <div class="tender-btn">
              <el-button type="primary" @click="gotoScreen">进入 大屏</el-button>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
    <!-- 界面 -->
    <el-dialog ref="drawer" title="编辑" :visible.sync="drawer" close-on-press-escape destroy-on-close>
      <div v-if="drawer" class="draw-body">
        <div class="wise-form">
          <el-form ref="ruleForm" :model="object" :rules="rules" :validate-on-rule-change="false" label-width="130px"
            label-suffix=":">
            <el-form-item label="项目名称" prop="name">
              <el-input v-model="object.name" placeholder="请输入项目名称" :maxlength="100" :disabled="true" show-word-limit
                clearable autofocus />
            </el-form-item>
            <el-form-item label="项目编号" prop="welderNumber">
              <el-input v-model="object.welderNumber" placeholder="请输入项目编号" :maxlength="100" show-word-limit clearable
                autofocus />
            </el-form-item>
            <el-form-item label="项目地址" prop="area">
              <wise-region v-model="object.area" :obj-keys="[
                  {
                    field: 'province',
                    key: 'province',
                    value: 'key',
                  },
                  {
                    field: 'provinceName',
                    key: 'province',
                    value: 'value',
                    tableShow: true,
                  },
                  {
                    field: 'city',
                    key: 'city',
                    value: 'key',
                  },
                  {
                    field: 'cityName',
                    key: 'city',
                    value: 'value',
                    tableShow: true,
                  },
                  {
                    field: 'county',
                    key: 'area',
                    value: 'key',
                  },
                  {
                    field: 'countryName',
                    key: 'area',
                    value: 'value',
                    tableShow: true,
                  },
                  {
                    field: 'street',
                    key: 'town',
                    value: 'key',
                  },
                  {
                    field: 'streetName',
                    key: 'town',
                    value: 'value',
                    tableShow: true,
                  },
                ]" @on-value="setValue" />
            </el-form-item>
            <el-form-item label="详细地址" prop="address">
              <el-input v-model="object.address" placeholder="请输入详细地址" :maxlength="100" show-word-limit clearable
                autofocus />
            </el-form-item>
            <el-form-item label="项目开始时间" prop="startTime">
              <wise-date v-model="object.startTime" type="datetime" format="yyyy-MM-dd HH:mm:ss" />
            </el-form-item>
            <el-form-item label="项目结束时间" prop="endTime">
              <wise-date v-model="object.endTime" type="datetime" format="yyyy-MM-dd HH:mm:ss" />
            </el-form-item>
            <el-form-item label="工艺规程编号" prop="craftsId">
              <el-select v-model="object.craftsId" filterable clearable placeholder="请选择工艺规程编号">
                <el-option v-for="item in craftsInfoList" :key="item.id" :label="item.craftsNumber" :value="item.id" />
              </el-select>
            </el-form-item>
            <el-form-item label="动火等级" prop="hotLevel">
              <el-input v-model="object.hotLevel" placeholder="请输入动火等级" :maxlength="100" show-word-limitclearable
                autofocus />
            </el-form-item>
            <el-form-item label="动火作业单位" prop="hotEntName">
              <el-input v-model="object.hotEntName" placeholder="请输入动火作业单位" :maxlength="100" show-word-limitclearable
                autofocus />
            </el-form-item>

            <el-form-item label="生产计划" prop="repairMethod">
              <el-input v-model="object.repairMethod" placeholder="请输入生产计划" :maxlength="100" show-word-limitclearable
                autofocus />
            </el-form-item>
            <el-form-item label="焊口总数量" prop="weldAllNumber">
              <el-input-number v-model="object.weldAllNumber" placeholder="请输入焊口总数量" :maxlength="100"
                show-word-limitclearable autofocus />
            </el-form-item>
            <el-form-item label="焊口完成数量" prop="weldFinshNumber">
              <el-input-number v-model="object.weldFinshNumber" placeholder="请输入焊口完成数量" :maxlength="100"
                show-word-limitclearable autofocus />
            </el-form-item>
            <el-form-item label="纵焊缝总数量" prop="portraitWeldAllNumber">
              <el-input-number v-model="object.portraitWeldAllNumber" placeholder="请输入焊口完成数量" :maxlength="100"
                show-word-limitclearable autofocus />
            </el-form-item>
            <el-form-item label="纵焊缝完成数量" prop="portraitWeldFinshNumber">
              <el-input-number v-model="object.portraitWeldFinshNumber" placeholder="请输入焊口完成数量" :maxlength="100"
                show-word-limitclearable autofocus />
            </el-form-item>
            <el-form-item label="环焊缝总数量" prop="cinctureWeldAllNumber">
              <el-input-number v-model="object.cinctureWeldAllNumber" placeholder="请输入焊口完成数量" :maxlength="100"
                show-word-limitclearable autofocus />
            </el-form-item>
            <el-form-item label="环焊缝完成数量" prop="cinctureWeldFinshNumber">
              <el-input-number v-model="object.cinctureWeldFinshNumber" placeholder="请输入焊口完成数量" :maxlength="100"
                show-word-limitclearable autofocus />
            </el-form-item>
            <el-form-item label="大屏名称" prop="screenName">
              <el-input v-model="object.screenName" placeholder="请输入大屏名称" :maxlength="100" show-word-limitclearable
                autofocus />
            </el-form-item>
            <el-form-item label="大屏Logo" prop="logo">
              <wise-file v-model="object.logo" upload-type="image" :limit="1" :max-file-size="100 * 1024 * 1024" />
            </el-form-item>
            <el-form-item label="施工方案" prop="construction">
              <wise-file v-model="object.construction" upload-type="file" :limit="1" />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
              <el-button @click="resetForm('ruleForm')">重置</el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import permission from '../../directive/permission/index.js' // 权限判断指令
  import WiseRegion from '@/components/Crud/components/wiseRegion'
  import WiseDate from '@/components/Crud/components/wiseDate'
  import WiseFile from '@/components/Crud/components/wiseFile'
  import {
    postHandle
  } from '@/api'
  import store from '../../store'
  export default {
    name: 'DashboardAdmin',
    directives: {
      permission
    },
    components: {
      WiseFile,
      WiseDate,
      WiseRegion
    },
    data() {
      return {
        craftsInfoList: [],
        drawer: false,
        object: {
          name: null,
          screenName: null,
          logo: null,
          area: {},
          serialNum: null,
          province: null,
          city: null,
          county: null,
          street: null,
          provinceName: null,
          cityName: null,
          countryName: null,
          streetName: null,
          address: null,
          companyName: null,
          manager: null,
          typeCode: null,
          phone: null,
          file: [],
          remark: null,
          craftsId: null,
          welderNumber: null,
          userId: null,
          startTime: '',
          endTime: '',
          hotLevel: null,
          hotEntName: null,
          repairMethod: null,
          weldAllNumber: null,
          weldFinshNumber: null,
          portraitWeldAllNumber: null,
          portraitWeldFinshNumber: null,
          cinctureWeldAllNumber: null,
          cinctureWeldFinshNumber: null,
          construction: null
        },
        rules: {
          name: [{
            required: true,
            message: '请输入项目名称',
            trigger: 'blur'
          }],
          welderNumber: [{
            required: true,
            message: '请输入项目编号',
            trigger: 'blur'
          }],
          area: [{
            required: true,
            message: '请选择地址',
            trigger: 'blur'
          }],
          address: [{
            required: true,
            message: '请输入详细地址',
            trigger: 'blur'
          }],
          startTime: [{
            required: true,
            message: '请选择项目开始时间',
            trigger: 'blur'
          }],
          endTime: [{
            required: true,
            message: '请选择项目结束时间',
            trigger: 'blur'
          }],
          hotLevel: [{
            required: true,
            message: '请输入动火等级',
            trigger: 'blur'
          }],
          hotEntName: [{
            required: true,
            message: '请输入动火作业单位',
            trigger: 'blur'
          }],
          repairMethod: [{
            required: true,
            message: '请输入生产计划',
            trigger: 'blur'
          }],
        },

        fileList: []
      }
    },
    computed: {
      project() {
        return this.$store.state.project.object
      }
    },
    watch: {
      project(val) {
        this.project = val
      }
    },
    created() {
      this.getCraftsInfoList()
    },
    methods: {
      viewHandle() {
        this.$router.push({
          name: 'ENT-SCREEN'
        })
      },
      editHandle() {
        for (let key in this.project) {
          this.object[key] = this.project[key]
        }

        this.object.area = {
          province: {
            key: this.object.province,
            value: this.object.provinceName
          },
          city: {
            key: this.object.city,
            value: this.object.cityName
          },
          area: {
            key: this.object.county,
            value: this.object.countyName
          },
          town: {
            key: this.object.street,
            value: this.object.streetName
          }
        }
        this.drawer = true
      },
      submitForm(ruleForm) {
        this.$refs[ruleForm].validate((valid) => {
          if (valid) {
            postHandle(
                `/api/v1/welder-sbtx-second/project-info-comb/update/${this.object.id}`, {
                  obj: this.object
                }
              )
              .then((response) => {
                this.$message('操作成功')
                this.drawer = false
                this.$store.dispatch('project/getObject')
              })
              .catch((error) => {
                const data = error.response.data
                for (const key in data) {
                  this.$message.error(this.$t(key) + this.$t(data[key]))
                }
              })
          } else {
            console.log('error submit!!')
            return false
          }
        })
      },
      resetForm(ruleForm) {
        (this.object = {
          name: null,
          screenName: null,
          logo: null,
          serialNum: null,
          province: null,
          city: null,
          county: null,
          street: null,
          provinceName: null,
          cityName: null,
          countryName: null,
          streetName: null,
          address: null,
          companyName: null,
          manager: null,
          typeCode: null,
          phone: null,
          file: [],
          remark: null,
          craftsId: null,
          welderNumber: null,
          userId: null,
          startTime: '',
          endTime: '',
          hotLevel: null,
          hotEntName: null,
          repairMethod: null,
          weldAllNumber: null,
          weldFinshNumber: null,
          portraitWeldAllNumber: null,
          portraitWeldFinshNumber: null,
          cinctureWeldAllNumber: null,
          cinctureWeldFinshNumber: null,
          construction: null
        }),
        this.$refs[ruleForm].resetFields()
      },
      setValue(objVal) {
        if (objVal && objVal.length > 0) {
          objVal.forEach((item) => {
            this.$set(this.object, item.field, item.value)
          })
        }
      },
      getCraftsInfoList() {
        const req = {
          d: {
            page: {
              p: 1,
              ps: 9999
            }
          }
        }
        postHandle('/api/v1/welder-sbtx-second/crafts-info-comb/list', req).then((response) => {
          this.craftsInfoList = response.result
        })
      },
      gotoScreen() {
        this.$router.replace({
          name: 'ProjectScreen'
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
  .clearfix:after,
  .clearfix:before,
  .media:after,
  .media:before {
    display: table;
    content: " ";
  }

  .clearfix:after,
  .media:after {
    clear: both;
  }

  .admin-index .panel {
    background: #f5f5f5;
  }

  .admin-index .panel .panel-body {
    padding: 50px;
  }

  .admin-index .panel .panel-body .media .media-left {
    float: left;
  }

  .admin-index .panel .panel-body .media .media-body {
    overflow: hidden;
    padding-left: 30px;
  }

  .admin-index .panel .panel-body .media .media-body .name {
    color: #8f2d07;
    font-size: 38px;
    margin-top: 20px;
    margin-bottom: 10px;
  }

  .admin-index .panel .panel-body .media .media-body .txt {
    font-size: 20px;
    line-height: 20px;
    color: #000;
  }

  .user-bottom {
    width: 100%;
    height: 643px;
    background-color: #fff;
    position: relative;
  }

  .user-bottom .icon-part {
    width: 320px;
    height: 225px;
    margin: 0 auto;
    position: relative;
    top: 159px;
  }

  .user-bottom .icon-part .tip-more {
    height: 40px;
    font-size: 28px;
    font-weight: 400;
    color: #bbbbbb;
    line-height: 40px;
    text-align: center;
    margin-top: 43px;
  }

  .panel-group {
    margin-top: 18px;

    .card-panel-col {
      margin-bottom: 32px;
    }

    .card-panel {
      height: 108px;
      cursor: pointer;
      font-size: 12px;
      position: relative;
      overflow: hidden;
      color: #666;
      background: #fff;
      box-shadow: 4px 4px 40px rgba(0, 0, 0, 0.05);
      border-color: rgba(0, 0, 0, 0.05);

      &:hover {
        .card-panel-icon-wrapper {
          color: #fff;
        }

        .icon-people {
          background: #40c9c6;
        }

        .icon-message {
          background: #36a3f7;
        }

        .icon-money {
          background: #f4516c;
        }

        .icon-shopping {
          background: #34bfa3;
        }
      }

      .icon-people {
        color: #40c9c6;
      }

      .icon-message {
        color: #36a3f7;
      }

      .icon-money {
        color: #f4516c;
      }

      .icon-shopping {
        color: #34bfa3;
      }

      .card-panel-icon-wrapper {
        float: left;
        margin: 14px 0 0 14px;
        padding: 16px;
        transition: all 0.38s ease-out;
        border-radius: 6px;
      }

      .card-panel-icon {
        float: left;
        font-size: 48px;
      }

      .card-panel-description {
        float: right;
        font-weight: bold;
        margin: 26px;
        margin-left: 0px;

        .card-panel-text {
          line-height: 18px;
          color: rgba(0, 0, 0, 0.45);
          font-size: 16px;
          margin-bottom: 12px;
        }

        .card-panel-num {
          font-size: 20px;
        }
      }
    }
  }

  @media (max-width: 550px) {
    .card-panel-description {
      display: none;
    }

    .card-panel-icon-wrapper {
      float: none !important;
      width: 100%;
      height: 100%;
      margin: 0 !important;

      .svg-icon {
        display: block;
        margin: 14px auto !important;
        float: none !important;
      }
    }
  }

  .home-block {
    .home-info1 {
      padding: 30px 40px;
      margin-bottom: 25px;
      background: #fff;

      .media {
        .media-left {
          .el-icon-user-solid {
            font-size: 40px;
            line-height: 70px;
          }
        }

        .media-body {
          padding-top: 10px;

          .title {
            font-size: 20px;
            font-weight: 500;
            color: rgba(0, 0, 0, 0.85);
            line-height: 28px;
            margin-bottom: 5px;
          }

          .txt {
            font-size: 14px;
            font-weight: 400;
            color: rgba(0, 0, 0, 0.45);
            line-height: 22px;
          }
        }
      }

      .list-info {
        li {
          width: 20%;
          float: left;
          text-align: center;
          border-right: 1px solid #e9e9e9;
          cursor: pointer;

          &:last-child {
            border-right: 0;
          }

          .txt {
            font-size: 14px;
            font-weight: 400;
            color: rgba(0, 0, 0, 0.45);
            line-height: 22px;
          }

          .num {
            font-size: 30px;
            font-family: HelveticaNeue;
            color: rgba(0, 0, 0, 0.85);
            line-height: 38px;
          }
        }
      }
    }

    .home-info2 {
      padding: 30px 40px;
      background: #fff;

      .audit-list {
        .item {
          padding: 20px;
          border: 1px solid #eee;
          margin-bottom: 20px;

          .title {
            font-size: 16px;
            font-weight: 500;
            color: rgba(85, 85, 85, 1);
            line-height: 20px;
            margin-bottom: 10px;
            width: 360px;
          }

          .depart {
            font-size: 14px;
            font-weight: 500;
            color: rgba(85, 85, 85, 1);
            line-height: 20px;
            margin-bottom: 10px;

            .name {
              padding-right: 10px;
            }
          }

          .txt {
            font-size: 12px;
            font-weight: 400;
            color: rgba(0, 0, 0, 0.25);
            line-height: 20px;
          }

          .time {
            font-size: 12px;
            font-weight: 400;
            color: rgba(0, 0, 0, 0.25);
            line-height: 20px;
            margin-top: 40px;
          }

          &:hover {
            background: rgba(216, 216, 216, 0.13);
            border: 1px solid #979797;
          }
        }
      }
    }
  }
</style>